package com.aplink.generic.controller;

import android.app.Application;

import com.aplink.dellcommercial.R;
import com.aplink.dellcommercial.configuration.DellParameter;
import com.aplink.generic.database.DatabaseManager;

public abstract class AppGenericController extends Application {

    /******* DONT CHANGE BELOW CODE IF YOU ARE NOT A FRAMEWORK DEVELOPER ***********/
    /**
     * *************************************************************************
     * **************************************
     */

    // apply Singleton pattern with synchronisation to escape multi-thread
    protected static AppGenericController instance;

    public static AppGenericController getInstance() {
        return instance;
    }

    /**
     * AppController is the highest level of the app It is used as the template
     * to write any APLink mobile project based on the configurable framework
     * it's defined as in the application's manifest file <application>
     * AppController is an unique instance through the app's lifecycle here is
     * brief list of its features
     * ***********************************************
     * ******************************** - create database for only one time * -
     * create session manager to use in any activity * - create menu for the app
     * by config * - manage workflowControllers * - deal with synchronisation
     * data between local and server sides * - deal with local authentication
     * and expiration from server side *
     * ****************************************
     * ***************************************
     */

    // for project's developers perspective, please just edit in initProject
    // function as you want
    public abstract void initProject();

    private DatabaseManager mDatabaseManager;

    @Override
    public void onCreate() {
        super.onCreate();

        // this line is to make sure instance is unique and not be null
        instance = this;
        instance.initProject();
        mDatabaseManager = new DatabaseManager( getApplicationContext(), DellParameter.DATABASE_NAME,
                DellParameter.DATABASE_VERSION, R.raw.table_structures,
                R.raw.table_datas );
    }

    public DatabaseManager getDatabaseManager() {
        return mDatabaseManager;
    }
}
